<% '菜单生成%>
<!--#include file="../Include/Common.All.asp"-->
<!--#include file="../Include/Conn.asp"-->
<% call OpenConn%>

<!--#include file="../Include/Common.Security.asp"-->
<!--#include file="../Include/MD5.asp"-->
<!--#include file="../Include/JSON_2.0.2.asp"-->
<!--#include file="../Include/JSON_UTIL_0.1.1.asp"-->

<%
Private Function GetMenuJsonByUserID(UserId, resPPath)
''查找某个用户对应的权限对应的资源的信息，生成菜单
''Response.Write "--<<<" & UserId & "-----" & resPPath & ">>>---"
	Dim jsonObj_navg_list 
	Set jsonObj_navg_list =  jsArray()

	''添加导航信息 
	
 
	Dim rsObjH,strSql
	 Set rsObjT = Server.CreateObject("ADODB.Recordset")
	strSql=""
	strSql=strSql & " SELECT DISTINCT T_RES.* "
	strSql=strSql & " FROM T_RES INNER JOIN T_ROLE_RES INNER JOIN  T_USER_ROLE "
	strSql=strSql & " ON T_ROLE_RES.role_id = T_USER_ROLE.role_id ON T_RES.id = T_ROLE_RES.res_id "
	strSql=strSql & " WHERE (T_USER_ROLE.user_id ="&UserId&") AND (T_RES.res_ppath = '"& resPPath &"') "
	strSql=strSql & " ORDER BY T_RES.res_ppath, T_RES.meun_num "
	''Response.Write strSql&"-----"
	rsObjT.Open strSql, Conn, 1, 3
			If rsObjT.BOF And rsObjT.EOF Then 
				'nothing
			'end if	 
			'UserID=ReplaceBadChar(Trim(rsObjT("UserID")))
		 	else 
	      Do While Not rsObjT.EOF
	        if ("0_"=resPPath)then 
	        	'' Response.Write strSql&"-----"
	        		Set jsonObj_navg_list(Null) = jsObject()
							jsonObj_navg_list(Null)("txt") = rsObjT("meun_name")
							jsonObj_navg_list(Null)("name") = rsObjT("meun_code")
							jsonObj_navg_list(Null)("href") = rsObjT("res_url")			
	
							Set	jsonObj_navg_list(Null)("menu") = GetMenuJsonByUserID(UserId,rsObjT("res_ppath")&rsObjT("id")&"_")
	        else 
							Set jsonObj_navg_list(Null) = jsObject()
							jsonObj_navg_list(Null)("txt")= rsObjT("meun_name")
							jsonObj_navg_list(Null)("href")= rsObjT("res_url")
	        end if 
	     		rsObjT.MoveNext 
	          '''If i >= MaxPerPage Then Exit Do
	      Loop 
			end if 
			rsObjT.close
			Set rsObjT = Nothing 

 '释放数据库链接
	''call CloseConn	 
	Set GetMenuJsonByUserID = jsonObj_navg_list



End Function
%>

<%
	'定义json对象
	Dim jsonObj,jsonObj_user,jsonObj_navg_list,jsonObj_temp
	Set jsonObj = jsObject()
	
	Set jsonObj_user = jsObject()
	''添加用户信息
	jsonObj_user("UserID") = ReplaceBadChar(Trim(Session("UserID"))) 
	jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
	Set jsonObj("customer") = jsonObj_user 	
	
	Set jsonObj_navg_list =  jsArray()
	''添加导航信息
	Set jsonObj("navg_list") = GetMenuJsonByUserID(Session("UserID"),"0_") 	 
	
	'输出json对象
	jsonObj.Flush
	''Response.Write strSql&"-----"
	
%>
<%
	
''{navg_list:[	
''				{txt:"我的控制台",name:"index",href:"/console/",sel:"on"
''					,menu:[
''						 {txt:"我的消息",href:"/console/center/message.php"}
''						,{txt:"我的订单",href:"/console/center/order.php"}
''						,{txt:"我的待注域名",href:"/console/center/pending.php"}
''					]
''				}
''			 ,{txt:"账务管理",name:"payment",href:"/console/payment/pay.php",sel:""
''					,menu:[
''						 {txt:"护照充值",href:"/console/center/1.php"}
''						,{txt:"账务查询",href:"/console/center/2.php"}
''						,{txt:"索取发票",href:"/console/center/3.php"}
''					]
''				}
''			]
''		}
''		
		%>
